#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e5+1000;
typedef long long LL;
LL a[maxn],b[maxn];
bool vis[maxn];
bool cmp(LL A,LL B){
    return A>B;
}
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    LL n,m;cin>>n>>m;
    for(LL i=1;i<=max(n,m);i++) a[i]=b[i]=vis[i]=0;
    for(LL i=m;i<=n;i++) b[i]=1e18;
    for(LL i=1;i<=n;i++) cin>>a[i];
    for(LL i=1;i<=m;i++) cin>>b[i];
    sort(a+1,a+1+n,cmp);
   /// for(LL i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
    LL sum=0;
    for(LL i=1;i<=n;i++){
        if(b[i]<b[a[i]]&&!vis[i]){
           vis[i]=true;
           ///cout<<"i="<<i<<endl;
           sum+=b[i];
        }
        else{
      ///      cout<<"i="<<i<<endl;
           sum+=b[a[i]];
        }
      ///  debug(sum);
    }
    cout<<sum<<endl;
  }
return 0;
}
